home *** CD-ROM | disk | FTP | other *** search
- /*
- event loop
- */
-
- #include "sp.h"
- #include "sc_event.h"
- #include "sp_menu.h"
-
- /*
- something was done that will cause the menus to need updating
- */
- void bad_menu(void);
- void bad_menu()
- {menu_ok=FALSE;
- }
-
- void fix_menu(void);
- void fix_menu()
- {WindowPeek xFrontWindow;
- int edit_on;
- edit_on=TRUE; /*assume edit menu should be on*/
- menu_ok=TRUE; /*we fill fix the menus now*/
- xFrontWindow=(WindowPeek)FrontWindow(); /*get the front window*/
- if(xFrontWindow==NIL) /*is there a front window?*/
- edit_on=FALSE; /*no, so we can't edit it*/
- else
- if(xFrontWindow->windowKind >= 0) /*is there a desk accessory?*/
- edit_on=FALSE; /*it is ok to edit that*/
-
- if(edit_on) {
- EnableItem(menu_handles[MENU_edit],0); /*enable the edit menu*/
- EnableItem(menu_handles[MENU_file],FILE_close);
- }
- else {
- DisableItem(menu_handles[MENU_edit],0); /*disable the edit menu*/
- DisableItem(menu_handles[MENU_file],FILE_close);
- }
-
- DisableItem(menu_handles[MENU_file],FILE_new);
- DisableItem(menu_handles[MENU_file],FILE_open);
-
- DrawMenuBar();
- }
-
-
- /*
- start up a desk accessory
- */
- void do_deskacc(int);
- void do_deskacc(item)
- int item;
- {GrafPtr savedPort;
- Str255 desk_acc_name;
- int temp;
-
- GetPort(&savedPort);
- bad_menu();
-
- /*find the name of desk accessory*/
- GetItem(menu_handles[MENU_apple],item,&desk_acc_name);
- temp = OpenDeskAcc(desk_acc_name); /*open the desk accessory*/
-
- SetPort(&savedPort);
- }
-
- /*
- select an item from the apple menu
- */
- void do_apple_cmd(int);
- void do_apple_cmd(item)
- int item;
- {if(item==APPLE_about){
- doabout();
- #ifdef xxxyyy
- UnloadSeg(&doabout);
- #endif
- }
- else
- do_deskacc(item);
- }
-
- void do_file_cmd(int);
- void do_file_cmd(fitem)
- int fitem;
- {register WindowPeek xFrontWindow;
- xFrontWindow = (WindowPeek)FrontWindow(); /*see what the front window is*/
- switch(fitem) {
- case FILE_new:
- break;
- case FILE_open:
- break;
- case FILE_close: {
- if(xFrontWindow==NIL) /*if have a front window*/
- break;
- if(xFrontWindow->windowKind >= 0) /*and it is a desk acc*/
- break;
- CloseDeskAcc(xFrontWindow->windowKind);
- bad_menu();
- }
- break;
- case FILE_quit:
- want_done=TRUE; /*say we want to quit*/
- break;
- }
- }
-
- void do_edit_cmd(int);
- void do_edit_cmd(e_item)
- int e_item;
- {if(SystemEdit(e_item-1)) /*edit a system window?*/
- return; /*yes, fine SystemEdit did the work*/
- }
-
- void do_cmd(uint32);
- void do_cmd(a_cmd)
- uint32 a_cmd;
- {register uint16 a_menu,a_menu_item;
- a_menu=HiWord(a_cmd); /*see which menu*/
- if(a_menu==0)
- return;
-
- a_menu -= gl.res_base; /*adjust to zero based indexing*/
- a_menu_item=LoWord(a_cmd); /*get the menu index*/
- switch(a_menu) {
- case MENU_apple: /*about, desk accessories*/
- do_apple_cmd(a_menu_item);
- break;
- case MENU_file : /*file commands, open, close, quit etc*/
- do_file_cmd(a_menu_item);
- break;
- case MENU_edit :
- do_edit_cmd(a_menu_item); /*edit commands, cut, paste etc*/
- break;
- case MENU_seer :
- do_seer_menu(a_menu_item); /*the seer menu*/
- break;
- }
- HiliteMenu(0); /*unhighlight the selected menu*/
- }
-
- /*handle a key down event*/
- void e_key_down(EventRecord *);
- void e_key_down(the_event)
- EventRecord *the_event;
- {char char_in;
- /*get character typed in*/
- char_in = the_event->message & charCodeMask;
- /*want to do a menu command?*/
- if((the_event->modifiers & cmdKey) != 0)
- do_cmd(MenuKey(char_in)); /*yes, menu command via command and key*/
- }
-
-
- /*handle a mouse down event*/
- void e_mouse_down (EventRecord *);
- void e_mouse_down (the_event)
- EventRecord *the_event;
- {WindowPtr the_window;
- /*set the_window to the WindowPtr for where mouse event was*/
- switch(FindWindow(the_event->where,&the_window)) {
- case inDesk: /*mouse down on desktop*/
- break;
-
- case inMenuBar: /*pulling down a menu*/
- do_cmd(MenuSelect(the_event->where));
- break;
-
- case inSysWindow : /*click in a desk accessory*/
- SystemClick(the_event,the_window);
- bad_menu();
- break;
-
- case inContent: /*mouse down in a window*/
- if(the_window!=FrontWindow())
- SelectWindow(the_window);
- else
- e_down_content(the_event);
- break;
-
- case inDrag: /*in title bar for dragging*/
- DragWindow(the_window,the_event->where,&dragRect);
- break;
-
- case inGrow: /*in grow box for resizing*/
- e_grow(the_event->where);
- break;
-
- case inGoAway: /*in goaway for closing*/
- if (TrackGoAway(the_window,the_event->where))
- want_done=TRUE; /*say we want to quit*/
- break;
-
- case inZoomIn: /*shrink to normal size*/
- break;
-
- case inZoomOut: /*expand window to full size*/
- break;
- }
- }
-
- /*an event has come in, process it*/
- void do_event(EventRecord *);
- void do_event(the_event)
- register EventRecord *the_event;
- {switch(the_event->what) {
- case mouseDown:
- e_mouse_down(the_event);
- break;
- case mouseUp:
- break;
- case autoKey:
- case keyDown:
- e_key_down(the_event);
- break;
- case keyUp:
- break;
- case updateEvt:
- e_update_event(the_event);
- break;
- case diskEvt:
- break;
- case activateEvt:
- bad_menu();
- if((((WindowPeek)the_event->message)->windowKind)!=gl.win_ref_num)
- break; /*don't care about da windows*/
- if(the_event->modifiers & activeFlag) /*activate?*/
- e_activate((WindowPtr)the_event->message);
- else
- e_deactivate((WindowPtr)the_event->message);
- break;
- case networkEvt:
- case driverEvt:
- case app1Evt:
- case app2Evt:
- case app3Evt:
- case app4Evt:
- break;
- }
- }
-
- /*loop till it's time to quit the program processing events*/
- void event_loop()
- {EventRecord the_event;
- want_done=false; /*don't want to quit yet*/
- bad_menu(); /*the menus need updating*/
- while (!want_done){ /*loop till we quit*/
- check_paks_in_Q();
- scope_tick();
- SystemTask(); /*keep the background tasks happy*/
- if(!menu_ok) /*need to fix the menus?*/
- fix_menu(); /*yes, fix them*/
- if(GetNextEvent(everyEvent,&the_event)) /*if have an event set the_event*/
- do_event(&the_event); /*got an event, process it*/
- }
- }
-